package cn.itcast.goods.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import cn.itcast.goods.admin.admin.domain.Admin;

public class AdminLoginFilter implements Filter {

	public void destroy() {}

	
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
		Admin admin = (Admin) req.getSession().getAttribute("admin");
		if(admin == null ) {
			req.setAttribute("code", "error");
			req.setAttribute("msg", "你还没有登陆！");
			req.getRequestDispatcher("/adminjsps/msg.jsp").forward(req, response);
		} else {
			chain.doFilter(req, response);
		}
	}

	
	public void init(FilterConfig fConfig) throws ServletException {}

}
